package com.kingtao.entry;

import com.kingtao.enums.NodeStatusEnums;
import com.kingtao.util.CoreData;
import lombok.Data;

import java.util.List;

/**
 * @Author: kingtao
 * @Date: 2023-07-24-10:02
 * @Description: node配置
 */
@Data
public class Node {

    //  节点编号
    private int id;

    //  节点配置
    private Peer peer;

    //  节点状态
    private volatile NodeStatusEnums status;

    //  节点信誉度
    private volatile double credit;

    //  leader的任期
    private volatile int LeaderCurrentTerm = 0;
    private volatile int SecondLeaderCurrentTerm = 0;

    //  日志提交的索引
    private int lastLogIndex;

    public Node(int id, Peer peer) {
        this.id = id;
        this.peer = peer;
        status = NodeStatusEnums.follower;
        credit = CoreData.CREDIT_INIT;
    }

    @Override
    public String toString() {
        return "{" + "Node: " + peer.toString() + ", id: " + id + ", status: " + status + ", credit: " + credit + "}\n";
    }
}
